package lyd;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Check if the robot fired its gun.
 *
 * @author Daniel Ly
 */
public class TestGunFire extends RobotTestBed {
  // Check to see if the CompetitiveRobot fires.
  boolean fired = false;

  /**
   * Specifies that SittingDuck and CompetitiveRobot are to be matched up in this test case.
   *
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,lyd.CompetitiveRobot";
  }

  /**
   * This test runs for 10 round.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * After each turn, check to see if the robot fired it's gun.
   *
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get the snapshot of the robot CompetitiveRobot 
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    if (robot.getGunHeat() > 0) {
      fired = true;
    }
  }

  /**
   * After the battle, check to see that the robot fired.
   *
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Robot fired it's gun", fired);
  
  }

}